package C6_5_BuilderComposite.before;

import java.util.List;

/**
 * @author xufy
 * @version 1.0
 **/
public class CatalogWriter {
    public String catalogXmlFor(Activity activity) {
        TagNode activityTag = new TagNode("activity");
        TagNode flavorsTag = new TagNode("flavors");
        activityTag.add(flavorsTag);
        for (int i = 0; i < activity.getFlavorCount(); i++) {
            TagNode flavorTag = new TagNode("flavor");
            flavorTag.add(flavorTag);
            Flavor flavor=activity.getFlavor(i);
            int requirementsCount=flavor.getRequirements().length;
            if(requirementsCount>0){
                TagNode requirementsTag=new TagNode("requirements");
                flavorTag.add(requirementsTag);
                for (int j = 0; j < requirementsCount; j++) {
                    Requirement requirement=flavor.getRequirements()[j];
                    TagNode requirementTag =new TagNode("requirement");
                    requirementTag.add(requirementTag);
                }
            }
        }
        return activityTag.toString();
    }
}

class Activity {
    private int flavorCount;
    List<Flavor> flavors;

    public int getFlavorCount() {
        return flavorCount;
    }

    public void setFlavorCount(int flavorCount) {
        this.flavorCount = flavorCount;
    }

    public Flavor getFlavor(int i) {
        return flavors.get(i);
    }

    public void setFlavors(List<Flavor> flavors) {
        this.flavors = flavors;
    }
}

class Flavor {

    Requirement[] requirements;


    public Requirement[] getRequirements() {
        return requirements;
    }

    public void setRequirements(Requirement[] requirements) {
        this.requirements = requirements;
    }

}
class Requirement{

}